package com.webserver.http;

import java.util.HashMap;
import java.util.Map;

/**
 * 当前类用于定义那些在HTTP协议中的规定内容，以便进行复用
 */
public class HttpContext {
    //回车符
    public static final char CR =13;
    //换行符
    public static final char LF =10;
    /*
    MIME类型映射
    key:资源后缀名.如：css.png.html
    value:该资源类型对应的MIME值. 如：text/css,image/png,text/html
     */
    private static Map<String,String> mimeMapping =new HashMap<>();

    static {
        //初始化所有静态属性的地方
        initMimeMapping();//初始化MIME映射的
    }
    private static void initMimeMapping(){
        mimeMapping.put("html","text/html");
        mimeMapping.put("css","text/css");
        mimeMapping.put("js","application/javascript");
        mimeMapping.put("png","image/png");
        mimeMapping.put("gif","image/gif");
        mimeMapping.put("jpg","image/jpeg");
    }
    /**
     * 根据资源后缀名获取对应的MIME值
     * @param ext   资源的后缀名,例如:css
     * @return      该资源对应的MIME值,例如:text/css
     */
    public static String getMimeType(String ext){
        return mimeMapping.get(ext);
    }
}
